/**
 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

const DBL_EPSILON : double = 1.0e-6;
function checkTestResult(actual : {{.item.result_type}}, expected : {{.item.result_type}}) : int {

{%- if item.result_type_nature == "Float" or item.result_type == "Double" or item.result_type == "double" or item.result_type == "float"%}
{%- if item.result_type == "Float" or item.result_type == "Double" %}
    if(expected.isNaN()) {
    if (actual.isNaN()) return 0;
    else return 1;
  }
{% else %}
  if({{.item.result_type|capitalize}}.isNaN(expected)) {
    if ({{.item.result_type|capitalize}}.isNaN(actual)) return 0;
    else return 1;
  }
{% endif %}

  if(expected == {{.item.result_type|capitalize}}.POSITIVE_INFINITY) {
    if (actual == {{.item.result_type|capitalize}}.POSITIVE_INFINITY) return 0;
    else return 1;
  }

  if(expected == {{.item.result_type|capitalize}}.NEGATIVE_INFINITY) {
    if (actual == {{.item.result_type|capitalize}}.NEGATIVE_INFINITY) return 0;
    else return 1;
  }
  if (actual == expected) {
    return 0;
  }
  let diff : double;
  if (actual > expected) {
    diff = actual - expected;
  } else {
   diff = expected - actual;
  }
  if (diff < DBL_EPSILON) {
    return 0;
  } else {
    return 1; 
}
{% else %}
  if (actual == expected) return 0;
  return 1;
{% endif %}

}
